//发送验证码时添加cookie 
function addCookie(name,value,expiresHours){  
    var cookieString=name+"="+escape(value);  
    //判断是否设置过期时间,0代表关闭浏览器时失效     
    if(expiresHours>0){  
        var date=new Date();  
        date.setTime(date.getTime()+expiresHours*1000);  
        cookieString=cookieString+";expires=" + date.toUTCString();  
    }  
        document.cookie=cookieString;  
}  //修改cookie的值 
function editCookie(name,value,expiresHours){  
    var cookieString=name+"="+escape(value);  
    if(expiresHours>0){  
      var date=new Date();  
      date.setTime(date.getTime()+expiresHours*1000); //单位是毫秒       cookieString=cookieString+";expires=" + date.toGMTString();  
    }  
      document.cookie=cookieString;  
}  //根据名字获取cookie的值 
function getCookieValue(name){  
      var strCookie=document.cookie;  
      var arrCookie=strCookie.split("; ");  
      for(var i=0;i<arrCookie.length;i++){  
        var arr=arrCookie[i].split("=");  
        if(arr[0]==name){ 
          return unescape(arr[1]); 
          break; 
        }else{ 
             return "";  
             break; 
         }  
      }  
}

var wait;
function time(getVerify,reGetVerify) {
	wait=getCookieValue("secondsremained"); 
    if (wait == 0) {
    	$("#"+getVerify+"").removeAttr("style");
    	$("#"+reGetVerify+"").attr("style","display:none");
        wait = 60;
        clearSession();
    } else {
    	$("#"+reGetVerify+"").removeAttr("style");
    	$("#"+getVerify+"").attr("style","display:none");
    	$("#"+reGetVerify+"").text("重新发送(" + wait + ")");
        wait--;
        editCookie("secondsremained",wait,wait+1); 
        setTimeout(function() {
            time(getVerify,reGetVerify);
        },
        1000);
    }
}
var waitPay;
function timePay(getVerify,reGetVerify) {
	waitPay=getCookieValue("secondsremained");
    if (waitPay == 0) {
    	$("#"+getVerify+"").removeAttr("style");
    	$("#"+reGetVerify+"").attr("style","display:none");
    	waitPay = 60;
    	clearSession();
    } else {
    	$("#"+reGetVerify+"").removeAttr("style");
    	$("#"+getVerify+"").attr("style","display:none");
    	$("#"+reGetVerify+"").text("重新发送(" + waitPay + ")");
    	waitPay--;
    	editCookie("secondsremained",waitPay,waitPay+1); 
        setTimeout(function() {
        	timePay(getVerify,reGetVerify);
        },
        1000);
    }
}
function clearSession(){
	$.ajax({
	    cache: true,
	    type: "POST",
	    url:js.path()+"/user/clearSession.do",
	    //data:{account:account,status:3},
	    async: true,
	    success: function(data){
	    }
	});
}
